package com.cucn.mms.common.controller;

import java.util.Map;

import com.cucn.mms.common.common.R;
import com.cucn.mms.common.service.Interface.PictureManageService;
import com.cucn.mms.domain.PictureManage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.cucn.mms.exception.MMSServiceException;

/**
 * 视频管理请求处理
 *
 * @author Ken
 */
@Controller
@RequestMapping(value = "/**/pitureManage")
@Slf4j
public class PictureManageController
{

	@Autowired
	private PictureManageService pictureManageService;


	/**
	 * 可指定媒资信息查询
	 *
	 * @param keyword
	 *            查询关键字
	 * @param searchType
	 *            查询类型 //
	 * @param offset
	 *            分页偏移值
	 * @param limit
	 *            分页大小
	 * @return 结果的一个Map，其中： key为 rows 的代表记录数据；key 为 total 代表结果记录的数量
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "getPitureList", method = RequestMethod.GET)
	public @ResponseBody Map<String, Object> getPictureList(@RequestParam("keyword") String keyword,
															@RequestParam("searchType") String searchType,
															@RequestParam("offset") int offset,
															@RequestParam("limit") int limit) throws MMSServiceException {
		log.info("获取图片列表，查询关键字：{}，查询条件：{}，分页起始页：{}，分页长度：{}",keyword,searchType,offset,limit);

		Map<String, Object> map = pictureManageService.selectPictureByType(keyword, searchType, offset, limit);
		return map;
	}

	@PostMapping("updatePitureRecord")
	public @ResponseBody Map<String, Object> updatePictureRecord(@RequestBody PictureManage pictureManage){
		log.info("更新图片数据：{}",pictureManage.toString());

		if(pictureManage.getPitureId() == null){
			return R.error();
		}
		Map<String, Object> map = pictureManageService.updatePictureRecord(pictureManage);
		return map;
	}

	@GetMapping("deletePitureRecord")
	public @ResponseBody Map<String, Object> deletePictureRecord(@RequestParam("pitureId") Integer pictureId){
		log.info("删除图片数据id:{}",pictureId);

		if(pictureId == null){
			return R.error();
		}
		Map<String, Object> map = pictureManageService.deletePictureRecord(pictureId);
		return map;
	}

	@PostMapping("addPiture")
	public @ResponseBody Map<String, Object> addPicture(PictureManage pictureManage){
		log.info("新增图片：{}",pictureManage.toString());

		Map<String, Object> map = pictureManageService.addPicture(pictureManage);
		return map;
	}

}
